Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dashboard various fixes #78

Merged
merged 33 commits into from
May 27, 2024

Conversation

adelinaenache
Copy link
Collaborator

@adelinaenache adelinaenache commented May 18, 2024

  • Move reviews endpoints in specific controllers
  • Move connections endpoint in specific controllers
  • Add ability to follow/unfollow an user
  • Add ability to like a review
  • Add state to reviews
  • Uploads base64 profile pictures because of expo image picker limitations for web

Fixes #80
Fixes #79
Fixes #74

@adelinaenache adelinaenache force-pushed the dashboard-various-fixes branch from 4d28b2e to 859906c Compare May 22, 2024 15:03
Copy link
Collaborator

@rajdip-b rajdip-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One general suggestion that I would like you to have is, since we are using prisma, using a DTO for returning data doesn't really make much sense and seems like extra code.

/**
* Create a connection between current User and another user.
*/
@Post('/connect/:userId')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better name for this would be add. Similarly, for the delete endpoint it can be remove. This will look pretty meaningful when put together:

  • GET /api/connection/add/:userId
  • DELETE /api/connection/remove/:userId

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it is right now it is in alignment with RESTful standards. The verb "POST" signifies a resource creation, and DELETE signifies a resource removal.
Adding verbs like add and remove in the endpoint path can be redundant and not as clean as using HTTP methods to indicate the action. RESTful best practices suggest using nouns in URLs and verbs in HTTP methods.

https://mglaman.dev/blog/post-or-put-patch-and-delete-urls-are-cheap-api-design-matters
https://www.mscharhag.com/api-design/rest-deleting-resources

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I know it is bit of a gamble in here. The thing is, feels that the connect word might specify an action and not a resource. Truly we can get rid of add and delete since the methods will signify that. I think we can go with /api/connection/:userId as the path and DELETE and POST as the methods?

import { Public } from 'src/decorators/public.decorator';

@ApiBearerAuth()
@Controller('connections')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our existing endpoints use singular in the controller name, so we should be sticking to connection in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a larger discussions. I think it makes sense to have user since in that controller we're usually dealing with a single user.
Put in reviews and connections we are usually dealing with multiple resources. See: Google's api design guidelines
and
this StackOverflow discussion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense

/**
* Get a connection.
*/
@Get('/:userId')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about this usecase. Can you link a screenshot/url?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay!

@Public()
@ApiBadRequestResponse()
async searchUser(
@Param('query') query: string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can add an alphanumeric regex check in here so that users cant use SQL injection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If prisma wouldn't be Sql injection safe out of the box all of our endpoint would be vulnerable for such a thing since we're not doing any kind of prevention for this anywhere.
Glad that is safe out of the box >.<
https://stackoverflow.com/questions/73943274/prisma-findunique-is-sql-injection-safe

@adelinaenache
Copy link
Collaborator Author

One general suggestion that I would like you to have is, since we are using prisma, using a DTO for returning data doesn't really make much sense and seems like extra code.

It does make sense to use. DTO because:

  1. Sometimes prisma types are different of what we actually want to send to the frontend (and sometimes include extra post processing, like calculating some fields or deleting fileds).
  2. DTO's are automatically interfered by the Swagger plugin, so we don't need to annotate things with @ApiProperty() .
  3. We can make nestjs automatically strip away extra properties based on DTO's, so we're making sure that extra props are never sent

@rajdip-b
Copy link
Collaborator

One general suggestion that I would like you to have is, since we are using prisma, using a DTO for returning data doesn't really make much sense and seems like extra code.

It does make sense to use. DTO because:

1. Sometimes prisma types are different of what we actually want to send to the frontend (and sometimes include extra post processing, like calculating some fields or deleting fileds).

2. DTO's are automatically interfered by the Swagger plugin, so we don't need to annotate things with `@ApiProperty()` .

3. We can make nestjs automatically strip away extra properties based on DTO's, so we're making sure that extra props are never sent

Okay! Cool! Would you think it would be good idea to seperate the request and response dtos in two separate folders under the dto folder?

@adelinaenache
Copy link
Collaborator Author

One general suggestion that I would like you to have is, since we are using prisma, using a DTO for returning data doesn't really make much sense and seems like extra code.

It does make sense to use. DTO because:

1. Sometimes prisma types are different of what we actually want to send to the frontend (and sometimes include extra post processing, like calculating some fields or deleting fileds).

2. DTO's are automatically interfered by the Swagger plugin, so we don't need to annotate things with `@ApiProperty()` .

3. We can make nestjs automatically strip away extra properties based on DTO's, so we're making sure that extra props are never sent

Okay! Cool! Would you think it would be good idea to seperate the request and response dtos in two separate folders under the dto folder?

No, not necessarily. I feel like that would just create more overhead in the development since we usually have just one output DTO (that is why I implemented that transform... method in services, and the file names are enough to know which dto are you looking at (ie update, create, etc)

@rajdip-b
Copy link
Collaborator

rajdip-b commented May 24, 2024

we usually have just one output DTO (that is why I implemented that transform... method in services

The point im trying to make here is, say the number of endpoints grow. For the simplest of example, lets take the example of retrieving a list of items, and a specific item. For a specific item, you would want to have much more detailed data, and sometimes even nested data. For lists, you wont bother sending the entire thing, but just partial information that is needed by the UI. So if i call this entity as Item, we can have two DTOs - ItemDTO and ItemListDTO. The names are self-explanatory. In this case, we can drop the transform function and solely rely on the class types. You can refer to this. I feel it will be much more cleaner that way.

No, not necessarily. I feel like that would just create more overhead in the development

When we are trying to create resources, we will be sending in details like name, description, etc etc. We wont be having any ID or any nested mappings (most of the time). In this case, if we are relying on the same DTO for both creating and fetching our records, we will land up in trouble where the swagger parser will misunderstand what exactly it is that we need. Also, it won't make sense to use class validator annotations in fields of a dto class that is responsible for returning data. EDIT: I used the single dto approach in an enterprise and messed up the code real bad due to this exact same problem.

@hsb1007 hsb1007 marked this pull request as ready for review May 27, 2024 11:03
@hsb1007 hsb1007 merged commit fd45bbe into eronka:develop May 27, 2024
4 checks passed
hsb1007 added a commit that referenced this pull request May 30, 2024
* chore(ci): Made pipeline fixes (#60)

* Adding PR title and es lint, prettier, unit test and e2e test checks

* Adding commands based on package.json

* added husky

* order checks

* folder updates

* folder updates

* eslint check

* replaced

* Add pnpm

* refactored installation for pnpm

* push diff validate pr yml

* deleted commitlintrc file

* added makefile

* update working directory of ci

* update .gitignore

* update ci

* update ci

---------

Co-authored-by: Bhavya Jain <[email protected]>
Co-authored-by: Ben <[email protected]>

* improve workflow

* fixing pr title validation identation issue

* update readme (#62)

* test(api): Added cleanup test to user module (#61)

* added afterALl in user test

* update CI

* Update README.md

* Update README.md

* added redis (#63)

* refactor: Moved items of backend folder to root (#65)

* refactored backend folder

* fixed tests

* fixed tests

* fix: Migrate to ioredis package (#70)

* migrate to ioredis

* update lockfile

* fixed tests

* update CI workflow

* Update README.md

* Update README-backend.md

* feat: write-review-page (#71)

* Add joined at date for searched user

* Update user search query to respect respect http standards

* Enable cors

* minor fixes

* Correct relations

* Check if users are connected when doing an user search

* fix db structure

* fix namings

* feat: auth flow changes (#73)

* Add joined at date for searched user

* Update user search query to respect respect http standards

* Enable cors

* minor fixes

* Correct relations

* Check if users are connected when doing an user search

* fix db structure

* fix namings

* Use passwordless signup

* Return props needed for signin redirection

* feat: Added feature to search by social profile (#77)

* added feature to search by social profile

* add linkedin profile fetching functionality

* finishing touches

* delete user controller test file

* fixed inconsistencies in e2e tests

* made search user endpoint public

* feat: Emails are stored in lowercase (#82)

* feat: Emails are stored in lowercase

* organized code

* fix: dashboard various fixes (#78)

* Add joined at date for searched user

* Update user search query to respect respect http standards

* Correct relations

* Check if users are connected when doing an user search

* fix db structure

* Fix: is connection should be true when userId is in the followers

* Do not use mutler for uploading profile pics
* Context: React native web sends base64 images that cannot be parsed by mutler

* update review properties

* add get user endpoint

* use headline insted of jobtitle

* remove console logs

* remove console log

* Move reviwes in dedicated controller.
* Rename ratings to reviews
* Use ratings only for professionalism/communication/reliability
* Create reviews controller and service
* Remove route with */self.

* enable swagger plugin

* review db structure changes:
* change id from int to string
* add state
* add favorite review model

* Add ability to like/unlike reviews and review state

* add ability to modify and update own review

* feat: add connections controller and move specific endpoints from user controller here

* fix: review annonymous property

* fix: add isEmailVerified to connection

* fix rebase errors

* Move search by profile url in connections.
* Add authType property on connectionDto
* remove jobTitle property. Use headline everywhere

* Return transformed user when social account is already existen

* add logging

* fix reviews issues

* rename dto folder

* rename methods

* make only one DB query for craeting a connection

* change DTO folder to a random name (because gh is not case sensitive and doesn't see lowering the case of the file as an actual change)

* rename dto folder

* squash migrations

* fix tests

* feat: implement user settings endpoints (#84)

* feat: user profile  (#85)

* fix: Docker builds were not running due to module errors (#86)

* feat: implement push notifications (#87)

* feat: implement push notifications

* fix tests

---------

Co-authored-by: Rajdip Bhattacharya <[email protected]>
Co-authored-by: Bhavya Jain <[email protected]>
Co-authored-by: Ben <[email protected]>
Co-authored-by: Adelina Enache <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants